summaryrefslogtreecommitdiffstats
path: root/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/PicassoUtils.java
blob: 504dc5b6d955115bd39612ed39e58520d390f4fb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package org.yuzu.yuzu_emu.utils;

import android.graphics.Bitmap;
import android.net.Uri;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

import org.yuzu.yuzu_emu.YuzuApplication;
import org.yuzu.yuzu_emu.R;

import java.io.IOException;

import androidx.annotation.Nullable;

public class PicassoUtils {
    private static boolean mPicassoInitialized = false;

    public static void init() {
        if (mPicassoInitialized) {
            return;
        }
        Picasso picassoInstance = new Picasso.Builder(YuzuApplication.getAppContext())
                .addRequestHandler(new GameIconRequestHandler())
                .build();

        Picasso.setSingletonInstance(picassoInstance);
        mPicassoInitialized = true;
    }

    public static void loadGameIcon(ImageView imageView, String gamePath) {
        Picasso
                .get()
                .load(Uri.parse(gamePath))
                .fit()
                .centerInside()
                .config(Bitmap.Config.RGB_565)
                .error(R.drawable.no_icon)
                .transform(new PicassoRoundedCornersTransformation())
                .into(imageView);
    }

    // Blocking call. Load image from file and crop/resize it to fit in width x height.
    @Nullable
    public static Bitmap LoadBitmapFromFile(String uri, int width, int height) {
        try {
            return Picasso.get()
                    .load(Uri.parse(uri))
                    .config(Bitmap.Config.ARGB_8888)
                    .centerCrop()
                    .resize(width, height)
                    .get();
        } catch (IOException e) {
            return null;
        }
    }
}